<template>
  <div id="tmpl">
    <ul class="goodslist">
      <li v-for="item in list">
        <img :src="item.img_url">
        <p>{{item.title}}</p>
        <div class="content">
          <p>
            <span class="pirce">{{item.sell_price}}</span>
            <del>{{item.market_price}}</del>
          </p>
          <p>
            <span class="left">热卖中</span>
            <span class="right">剩{{item.stock_quantity}}件</span>
          </p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
  import { Toast } from 'mint-ui';
  import common from '../../kits/common.js';
  export default {
    data() {
      return {
        list: [],
        pageindex: 1
      }
    },
    created() {
      this.getgoods(this.pageindex);
    },
    methods: {
      getgoods(pageindex) {
        pageindex = pageindex || 1;

        var url = common.apidomain + '/api/getgoods?pageindex=' + pageindex;

        this.$http.get(url).then(function(res) {
          var body = res.body;
          if(body.status != 0) {
            Toast(body.message);
            return;
          }
          this.list = body.message;
        }) 
      }
    }
  }
</script>

<style scoped>
  .goodslist {
    width: 100%;
    padding: 0 10px;
  }
  .goodslist li {
    display: inline-block;
    width: 48%;
    margin-top: 4%;
    margin-right: 4%;
    border: 1px solid #ccc;
    text-align: center;
  }
  .goodslist li:nth-child(2n) {
    margin-right: 0;
  }
  .goodslist li img {
    width: 80%;
  }

  .goodslist li p {
    text-align: left;
  }
  .goodslist .content {
    /*height: 60px;*/
    background-color: #ccc;
  }
  .goodslist .content p {
    padding: 0 8px;
    line-height: 30px;
    overflow: hidden;
  }
  .goodslist .content .pirce {
    color: #f00;
    margin-right: 10px;
  }
  .goodslist .content .left {
    float: left;
  }
  .goodslist .content .right {
    float: right;
  }
</style>